package com.ruoyi.web.controller.applet;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.BdmCloudInventoryItem;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.vo.applet.AppletCloudInventoryVo;
import com.ruoyi.system.domain.vo.applet.CommodityDetailsVo;
import com.ruoyi.system.service.IBdmCloudInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 小程序云库存
 *
 * @author ruoyi
 * @date 2024-12-24
 */
@Validated
@RestController
@RequestMapping("/applet/cloudInventory")
public class AppletCloudInventoryController extends BaseController
{
    @Autowired
    private IBdmCloudInventoryService bdmCloudInventoryService;

    /**
     * 查询我的云库存列表
     * @return {@link AppletCloudInventoryVo}
     */
    @GetMapping("/listByUser")
    public AjaxResult list( )
    {
        AppletCloudInventoryVo appletCloudInventoryVo = bdmCloudInventoryService.listByUser();
        return success(appletCloudInventoryVo);
    }
    /**
     * 查询云库存明细
     * @return {@link BdmCloudInventoryItem}
     */
    @GetMapping("/listByCloudInventoryId")
    public TableDataInfo listByCloudInventoryId(BdmCloudInventoryItemDto bdmCloudInventoryItemDto)
    {
        startPage();
        List<BdmCloudInventoryItem> list = bdmCloudInventoryService.listByCloudInventoryId(bdmCloudInventoryItemDto);
        return getDataTable(list);
    }

    /**
     * 补货查看商品详情
     *  @return {@link CommodityDetailsVo}
     */
    @GetMapping("/getCommodityDetails")
    public AjaxResult getCommodityDetails(@Valid @NotNull(message = "商品编号是必填的") Long goodId){
        return success(bdmCloudInventoryService.getCommodityDetails(goodId));
    }



    /**
     * 云库存补货
     */
    @PostMapping("/cloudInventoryPurchase")
    public AjaxResult cloudInventoryPurchase(@Valid @RequestBody CloudInventoryPurchaseDto cloudInventoryPurchaseDto)
    {
        return success(bdmCloudInventoryService.cloudInventoryPurchase(cloudInventoryPurchaseDto));
    }



    /**
     * 云库存提货到线下
     */
    @PostMapping("/cloudInventoryPickup")
    public AjaxResult cloudInventoryPickup(@Valid @RequestBody CloudInventoryPickupDto cloudInventoryPickupDto)
    {
        return success(bdmCloudInventoryService.cloudInventoryPickup(cloudInventoryPickupDto));
    }

    /**
     * 云库存订单取消
     * @param bdmOrderDto
     * @return
     */
    @PostMapping("/cloudInventory")
    public AjaxResult cloudInventory(@RequestBody BdmOrderDto bdmOrderDto)
    {
        return bdmCloudInventoryService.cloudInventory(bdmOrderDto);
    }

    /**
     * 云库存余额支付
     * @param bdmOrderDto
     * @return
     */
    @PostMapping("/payCloudInventoryOrder")
    public AjaxResult payCloudInventoryOrder(@RequestBody BdmOrderDto bdmOrderDto){
        return bdmCloudInventoryService.payCloudInventoryOrder(bdmOrderDto.getOrderId());
    }

    /**
     * 云仓补货查询用户
     */
    @GetMapping("/getUser")
    public AjaxResult getUser(Long userId){
      SysUser sysUser = bdmCloudInventoryService.getUser(userId);
     return AjaxResult.success(sysUser);
    }

    /**
     * 云仓配货
     */
    @PostMapping("/cloudWarehouseReplenishment")
    public AjaxResult cloudWarehouseReplenishment(@RequestBody BdmCloudReplenishmentDto dto){
        return AjaxResult.success(bdmCloudInventoryService.cloudWarehouseReplenishment(dto));
    }

}
